﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace project2
{
    class Program
    {
        static void Main(string[] args)
        {
            double[] newoblongsides = { 1.1, 1.2 };
            double[] newsquaresides = { 1.1 };
            double[] newdeltasides = { 1.1, 1.2, 1.3 };
            try
            {
                shape newoblong = new shape(newoblongsides,"oblong");
                shape newsquare = new shape(newsquaresides, "square");
                shape newdelta = new shape(newdeltasides, "delta");
                ShapesCalculate fun = new ShapesCalculate();

                Console.WriteLine(fun.size_cal_fun(newoblong.get_name(), newoblong.get_sides()));

                Console.WriteLine(fun.size_cal_fun(newsquare.get_name(), newsquare.get_sides()));

                Console.WriteLine(fun.size_cal_fun(newdelta.get_name(), newdelta.get_sides()));
                Console.ReadKey();
            }
            catch
            {

            };
        }
    }

    public class shape
    {
        private double[] length_sides;
        private string name;
        public shape(double[] length_sides,string name)
        {
            this.length_sides = length_sides;
            this.name = name;
        }
        public string get_name()
        {
            return this.name;
        }
        public double[] get_sides()
        {
            return this.length_sides;
        }
    }

    public class factory
    {
        public shape createShape(string type,double[] sides)
        {
            for(int i = 0; i < sides.Length; i++)
            {
                if (sides[i] <= 0) throw new ArgumentException("输入的边长不能小于0");
            }
            switch (type)
            {
                case "oblong": return new shape(sides, "oblong");
                case "square": return new shape(sides, "square");
                case "delta": return new shape(sides, "delta");
                default:throw new ArgumentException("输入的类型不存在");
            }
        }
    }
  
    public class ShapesCalculate
    {
        public double size_cal_fun(string shape_name,double[] length_sides)//判断合法
        {
            if ("oblong".Equals(shape_name) && length_sides.Length == 2) return (length_sides[0] * length_sides[1]);
            if ("square".Equals(shape_name) && length_sides.Length == 1) return (length_sides[0] * length_sides[0]);
            if ("delta".Equals(shape_name) && length_sides.Length == 3 && length_sides[0] < length_sides[1] + length_sides[2]
                && length_sides[1] < length_sides[0] + length_sides[2] && length_sides[2] < length_sides[0] + length_sides[1])
            {
                double p = 0.5 * (length_sides[0] + length_sides[1] + length_sides[2]);
                return Convert.ToSingle(Math.Sqrt(p * (p - length_sides[0]) * (p - length_sides[1]) * (p - length_sides[2])));
            }
            else throw new ArgumentException("输入的边长不正确");

        }
    }
}
